<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>javascript获取经纬度</title>
  <script src="account/js/geolocation.js"></script>
</head>
<body>
  <div id="point"></div>
  <div id="address"></div>
</body>
</html>
<script>
  var mylocation = new geolocation();

  mylocation.getGeolocation({
    success: function(res) {
      document.getElementById('point').innerText ='获取的经纬度为:'+res.coords.longitude+','+res.coords.latitude;
      // 经纬度转地址
      mylocation.geocoder({
        latitude: res.coords.latitude,
        longitude: res.coords.longitude,
        success: function(rs) {
          document.getElementById('address').innerText ='经纬度转换为地址:'+rs.formatted_address;
        },
        error: function() {
          document.getElementById('address').innerText ='经纬度转换为地址失败';
        }
      });
    },
    error: function() {
      document.getElementById('point').innerText ='定位失败';
    }
  })
</script>